package com.atguigu.gmall.realtime.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 向phoenix中插入数据工具类
 */
public class PhoenixUtil {
    //向phoenix插入数据方法
    public static void executeSql(Connection connection,String upsertSQL){
        PreparedStatement ps = null;
        try {
            //获取执行对象
            ps = connection.prepareStatement(upsertSQL);
            //执行sql
            ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("向phoenix中插入数据异常");
        }finally {
            if (ps != null){
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if (connection != null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
